package model;

import entity.Province;
import iface.IModel;
import javax.swing.DefaultListModel;

/**
 *
 * @author Noi
 */
public class ProvinceListModel extends DefaultListModel<Province> implements IModel<Province> {
    private manager.Manager manager;
    
    public ProvinceListModel(manager.Manager manager) {
        this.manager = manager;
        this.loadDataToList();
    }
    
    private void loadDataToList() {
        for(int i = 0; i < this.manager.getProvinceManager().size(); i++) {
            if(this.manager.getProvinceManager().get(i).isStatus())
                this.addElement(this.manager.getProvinceManager().get(i));
        }
    }

    @Override
    public void add(Province province) {
        this.manager.getProvinceManager().add(province);
        this.addElement(province);
    }
    
    @Override
    public void replace(int index, Province province) {
        this.set(index, province);
    }

    @Override
    public void remove(Province obj) {
        this.manager.getProvinceManager().remove(obj);
        this.removeElement(obj);
    }

    @Override
    public void refresh() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
